import { eachNext } from '../../utils/index.js'
import { rayMix, raySegs } from '../arrayMix.js'
import { plainMatrix } from '../index.js'
import { segmentsIntr } from '../triangle.js'
// 多边形连接线
export const linkPoints = (points) => {
    let lps = []
    for (let i = 0; i < points.length - 1; i++) {
        let p = points[i]
        lps = [...lps, ...rayMix(p, points.slice(i + 1))]
    }
    return lps
}

// 不包含边连线段
export const linkSegments = (points) => {
    let segs = []
    for (let i = 0, len = points.length; i < len - 2; i++) {
        let p = points[i]
        segs.push(raySegs(p, points.slice(i + 2, i === 0 ? (len - 1) : len)))
    }
    return segs
}


// 多边形连接线交叉点
export const linkCrossPoints = (points) => {
    let segs = linkSegments(points)
    let lcps = []
    for (let i = 0; i < segs.length-1; i++) {
        let seg = segs[i]
        let others = segs.slice(i + 1)
        let osegs = plainMatrix(others)
        seg.forEach(u => {
            osegs.forEach(v => {
                let p = segmentsIntr(u, v)
                if (p) {
                    lcps.push(p)
                }
            })
        })
    }
    return lcps
}